function $ (id) {
    return document.getElementById(id);
}

function formatTags(name, tagname)
{
 if (document.selection)
   {
    var str = document.selection.createRange().text
    document.forms['dbform'].elements[name].focus()
    var sel = document.selection.createRange()
    sel.text = "<"+tagname+">"+str+"</"+tagname+">"
   }
  else if ((typeof document.forms['dbform'].elements[name].selectionStart) != 'undefined')
   {
    var textArea = document.forms['dbform'].elements[name]
    var selLength = textArea.textLength
    var selStart = textArea.selectionStart
    var selEnd = textArea.selectionEnd
    var scroll = textArea.scrollTop
    var str1 = (textArea.value).substring(0,selStart)
    var str2 = (textArea.value).substring(selStart, selEnd)
    var str3 = (textArea.value).substring(selEnd, selLength)
    textArea.value = str1+'<'+tagname+'>'+str2+'</'+tagname+'>'+str3
    textArea.selectionStart = str1.length
    textArea.selectionEnd = str1.length + 5 + str2.length + tagname.length * 2
    textArea.scrollTop = scroll
   }
  else input(name, '<'+tagname+'></'+tagname+'> ');
 }

function getSelectionXICS(name)
{
 if (document.selection)
   {
      return document.selection.createRange().text
   }
  else if ((typeof parent.opener.document.forms['dbform'].elements[name].selectionStart) != 'undefined')
   {
    var textArea = parent.opener.document.forms['dbform'].elements[name]
    var selLength = textArea.textLength
    var selStart = textArea.selectionStart
    var selEnd = textArea.selectionEnd
    var scroll = textArea.scrollTop
    return (textArea.value).substring(selStart, selEnd)
   }
 }

function insertLink(obj, url, name)
{
 if (document.selection)
   {
    var str = parent.opener.document.selection.createRange().text
    parent.opener.document.forms['dbform'].elements[name].focus()
    var sel = parent.opener.document.selection.createRange()
    sel.text = "<a href=\""+url+"\">"+str+"</a>"
   }
  else if ((typeof parent.opener.document.forms['dbform'].elements[name].selectionStart) != 'undefined')
   {
    var textArea = parent.opener.document.forms['dbform'].elements[name]
    var selLength = textArea.textLength
    var selStart = textArea.selectionStart
    var selEnd = textArea.selectionEnd
    var scroll = textArea.scrollTop
    var str1 = (textArea.value).substring(0,selStart)
    var str2 = (textArea.value).substring(selStart, selEnd)
    var str3 = (textArea.value).substring(selEnd, selLength)
    textArea.value = str1+"<a href=\""+url+"\">"+str2+"</a>"+str3
    textArea.selectionStart = str1.length
    textArea.selectionEnd = str1.length + 5 + str2.length + 10 + url.length
    textArea.scrollTop = scroll
   }
  else input_parent(name, '<'+tagname+'></'+tagname+'> ');
 }

function insertDownload(name, what)
{
 if (parent.opener.document.selection)
   {
    var str = parent.opener.document.selection.createRange().text
    parent.opener.document.forms['dbform'].elements[name].focus()
    var sel = parent.opener.document.selection.createRange()
    sel.text = what+str+"</a>"
   }
  else if ((typeof parent.opener.document.forms['dbform'].elements[name].selectionStart) != 'undefined')
   {
    var textArea = parent.opener.document.forms['dbform'].elements[name]
    var selLength = textArea.textLength
    var selStart = textArea.selectionStart
    var selEnd = textArea.selectionEnd
    var scroll = textArea.scrollTop
    var str1 = (textArea.value).substring(0,selStart)
    var str2 = (textArea.value).substring(selStart, selEnd)
    var str3 = (textArea.value).substring(selEnd, selLength)
    textArea.value = str1+what+str2+"</a>"+str3
    textArea.selectionStart = str1.length
    textArea.selectionEnd = str1.length + 5 + str2.length + 10 + url.length
    textArea.scrollTop = scroll
   }
  else input_parent(name, 'Hallo');
 }

 function input(name, what)
 {
  if (document.forms['dbform'].elements[name].createTextRange)
   {
    document.forms['dbform'].elements[name].focus()
    document.selection.createRange().duplicate().text = what
   }
  else if ((typeof document.forms['dbform'].elements[name].selectionStart) != 'undefined')
   {
    var tarea = document.forms['dbform'].elements[name]
    var scroll = tarea.scrollTop
    var selEnd = tarea.selectionEnd
    var txtLen = tarea.value.length
    var txtbefore = tarea.value.substring(0,selEnd)
    var txtafter =  tarea.value.substring(selEnd, txtLen)
    tarea.value = txtbefore + what + txtafter
    tarea.selectionStart = txtbefore.length + what.length
    tarea.selectionEnd = txtbefore.length + what.length
    tarea.scrollTop = scroll
   }
  else
   {
    var tarea = document.forms['dbform'].elements[name]
    var scroll = tarea.scrollTop    
    tarea.value += what
    tarea.scrollTop = scroll
  }
 }
 
 function input_parent(name, what)
 {
  if (parent.opener.document.forms['dbform'].elements[name].createTextRange)
   {
    parent.opener.document.forms['dbform'].elements[name].focus()
    parent.opener.document.selection.createRange().duplicate().text = what
   }
  else if ((typeof parent.opener.document.forms['dbform'].elements[name].selectionStart) != 'undefined')
   {
    var tarea = parent.opener.document.forms['dbform'].elements[name]
    var scroll = tarea.scrollTop
    var selEnd = tarea.selectionEnd
    var txtLen = tarea.value.length
    var txtbefore = tarea.value.substring(0,selEnd)
    var txtafter =  tarea.value.substring(selEnd, txtLen)
    tarea.value = txtbefore + what + txtafter
    tarea.selectionStart = txtbefore.length + what.length
    tarea.selectionEnd = txtbefore.length + what.length
    tarea.scrollTop = scroll
   }
  else
   {
    var tarea = parent.opener.document.forms['dbform'].elements[name]
    var scroll = tarea.scrollTop    
    tarea.value += what
    tarea.scrollTop = scroll
  }
 }
 
 function inputOpener(obj, what)
 {
  if (obj.createTextRange)
   {
    obj.focus()
    opener.document.selection.createRange().duplicate().text = what
   }
  else if ((typeof obj.selectionStart) != 'undefined')
   {
    var tarea = obj
    var scroll = tarea.scrollTop
    var selEnd = tarea.selectionEnd
    var txtLen = tarea.value.length
    var txtbefore = tarea.value.substring(0,selEnd)
    var txtafter =  tarea.value.substring(selEnd, txtLen)
    tarea.value = txtbefore + what + txtafter
    tarea.selectionStart = txtbefore.length + what.length
    tarea.selectionEnd = txtbefore.length + what.length
    tarea.scrollTop = scroll
   }
  else
   {
    var tarea = obj
    var scroll = tarea.scrollTop    
    tarea.value += what
    tarea.scrollTop = scroll
   }
 }

 function parseList(str,list)
 {
  str = str.replace( /^\s+/g, "" )
  if (str.indexOf('<'+list)==0 && str.indexOf('</'+list+'>')>-1)
  {
    //reparsen der selektierten Liste
  }
  else alert('Die Liste konnte nicht gelesen werden.')
 }
